
package com.tianbo.elfii.client.common;

import java.io.*;
import java.sql.*;
import java.text.*;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;

import com.tianbo.elfii.client.common.ElfiiCommonUtil.FeedBackType;
import com.tianbo.elfii.client.swingcomponentlib.unitcomponent.TitleLabel;


import java.awt.image.*;

/**  <pre>
     <b>类功能描述：</b><pre>
     完成 登录 功能要求。
     </pre>
     @version 1.0.1
     @author 高伟 
*/

public class ElfiiCommonLogin  {

    String headline="登录/注册";    

    JButton okButton;
    JButton backButton;

    JButton manButton;
    JButton womanButton;
    JButton comboxToggleButton;

    int comboxWidth=320;
    int comboxHeight=112;

    ElfiiCommonLoginCombox comboxPanel;

    JTextField birthYearField;
    int maxBirthYearSize=4;
    JTextField birthMonthField;
    int maxBirthMonthSize=2;
    JTextField birthDayField;
    int maxBirthDaySize=2;

    JTextField userNameField;
    int maxUserNameSize=9;
    UserNamePanel userNamePanel;
    
    JButton birthYearDecreaseBtn;
    JButton birthYearIncreaseBtn;
    
    JButton birthMonthDecreaseBtn;
    JButton birthMonthIncreaseBtn;
    
    JButton birthDateDecreaseBtn;
    JButton birthDateIncreaseBtn;
    
    int birthYear;
    int birthMonth;
    int birthDay;
    
    int nowYear;
    int nowMonth;
    int nowDay;
    
    JFrame mainFrame;
    ElfiiCommonRunInfo runInfo;

    Keyboard keyboard;

    public ElfiiCommonLogin() {}

    public void setRunInfo(ElfiiCommonRunInfo runInfo){
        this.runInfo=runInfo;
        this.mainFrame=runInfo.getMainFrame();
    } 

    class UserNameKeyboardChangeListener implements DocumentListener {
        public void insertUpdate(DocumentEvent evt){
            keyboard.setCheckInfo("",null);
            comboxPanel.setComboxHide(false);
            comboxPanel.setFiltString(userNameField.getText());
            comboxPanel.repaint();
            userNamePanel.repaint();
            //userNameField.setText("gaogao"); 这种方法会出异常，行不通
        }
        public void removeUpdate(DocumentEvent evt){
            keyboard.setCheckInfo("",null);
            comboxPanel.setComboxHide(false);
            comboxPanel.setFiltString(userNameField.getText());
            comboxPanel.repaint();
            userNamePanel.repaint();
        }
        public void changedUpdate(DocumentEvent evt){
            userNameField.setCaretPosition(userNameField.getText().length());
        }
    }
//
//    int count = 0;
//    class BirthYearKeyboardChangeListener implements DocumentListener {
//        public void insertUpdate(DocumentEvent evt) {
//            if (keyboard!=null) {
//            	System.out.println("insert update "+(count++));
//                checkTextValue("birth-year");}
//        }
//        public void removeUpdate(DocumentEvent evt){
//            if (keyboard!=null) 
//                checkTextValue("birth-year");
//        }
//        public void changedUpdate(DocumentEvent evt){}
//    }
//
//    class BirthMonthKeyboardChangeListener implements DocumentListener {
//        public void insertUpdate(DocumentEvent evt) {
//            if (keyboard!=null) 
//                checkTextValue("birth-month");
//        }
//        public void removeUpdate(DocumentEvent evt){
//            if (keyboard!=null) 
//                checkTextValue("birth-month");
//        }
//        public void changedUpdate(DocumentEvent evt){}
//    }
//
//    class BirthDayKeyboardChangeListener implements DocumentListener {
//        public void insertUpdate(DocumentEvent evt) {
//            if (keyboard!=null) 
//                checkTextValue("birth-day");
//        }
//        public void removeUpdate(DocumentEvent evt){
//            if (keyboard!=null) 
//                checkTextValue("birth-day");
//        }
//        public void changedUpdate(DocumentEvent evt){}
//    }

    class Keyboard extends ElfiiCommonLoginKeyboard {
        public void checkLeftCursorKey(String focusTextName,String textValue,int caretPosition){
            
        }
        public void checkRightCursorKey(String focusTextName,String textValue,int caretPosition){
            if (focusTextName.equals("user-name") && caretPosition>8) {
                userNameField.setText(userNameField.getText().substring(0,8));

                	keyboard.setCheckInfo("用户名最多为8位",1000);
                
            }
        }
        public void checkValueUpdate(String focusTextName,String textValue,int caretPosition){
            if (focusTextName.equals("user-name")){
                comboxPanel.setComboxHide(false);
                comboxPanel.setFiltString(textValue);
                comboxPanel.repaint();
                userNamePanel.repaint();
            }
        }
    }

    class UserNamePanel extends JPanel {
        int w=comboxWidth,h=67;

        public void paintComponent(Graphics g) {
            super.paintComponent(g);

            Graphics2D g2 = (Graphics2D) g ;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 

            g2.setColor(Color.black);
            g2.fillRect(0,2,w,h-4);

            if (comboxPanel.isComboxHide()==false){
                g2.setColor(Color.lightGray);
                g2.fillRect(0,h/2,w,h/2+1);
            }

            g2.setColor(Color.white);
            g2.fillRoundRect(0,2,w,h-4,30,30);

            g2.setColor(Color.gray);
            g2.setColor(new Color(120,120,120));
            g2.fillRoundRect(comboxWidth-100,8,95,h-16,35,35);
            g2.setColor(Color.white);
            g2.fillRect(w/2,2,w/2-43,h-4);

            g2.setStroke(new BasicStroke(8.0f));

            g2.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,24));

            g2.setColor(ElfiiCommonConstant.Elfii_Blue);
            for (int i=0; i<28; i++) 
               g2.drawString("-",15+i*9,60);

        }
        public Dimension getPreferredSize() {
            return (new Dimension(332,80));
        }
    }

    class UserBirthPanel extends JPanel {
        int w=comboxWidth-20,h=67;

        public void paintComponent(Graphics g) {
            super.paintComponent(g);

            Graphics2D g2 = (Graphics2D) g ;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 
            g2.setColor(Color.black);
            g2.fillRect(0,0,w,h);
            g2.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,20));

            g2.setColor(Color.white);
            g2.fillRoundRect(0,2,195,h-4,30,30);

            g2.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,24));
            g2.setColor(ElfiiCommonConstant.Elfii_Blue);
            g2.drawString("_",80,28);
            g2.drawString("_",133,28);

            for (int i=0; i<19; i++) 
               g2.drawString("-",11+i*9,60);

        }
        public Dimension getPreferredSize() {
            return (new Dimension(280,80));
        }
    }

//    class HeadlinePanel extends JPanel {
//        int w=600,h=20;
//
//        public void paintComponent(Graphics g) {
//            super.paintComponent(g);
//
//            Graphics2D g2 = (Graphics2D) g ;
//            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 
//            g2.setColor(Color.black);
//            g2.fillRect(0,0,w,h);
//            g2.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,24));
//            g2.setColor(Color.white);
//            g2.drawString("用户名",0,20);
//            g2.drawString("生日",335,20);
//        }
//        public Dimension getPreferredSize() {
//            return (new Dimension(w,h));
//        }
//    }

    public void setKeyboardTextFieldUserName(){
        keyboard.setTextField(userNameField,maxUserNameSize);
        keyboard.setFocusTextName("user-name");
        String str=userNameField.getText().trim();
        comboxPanel.setFiltString(str);
    }

    public void dealOkButton(){
    	System.out.println("okbtn");
        String userName=userNameField.getText().trim();
        String userBirth=birthYearField.getText()+"-"+birthMonthField.getText()+"-"+birthDayField.getText();
        String userSex="man";

//        String errStr=null;
//        try {
//            java.sql.Date dd=Date.valueOf(userBirth);
//            if (dd.toString().equals(userBirth)==false){
//                errStr="生日错误:"+userBirth;
//                keyboard.setCheckInfo(errStr,null);
//            }
//
//        } catch (Exception e) {
//            errStr="生日错误:"+userBirth;
//            keyboard.setCheckInfo(errStr,null);
//        }
        if (userName.trim().length()==0){
        	return;
//            errStr="用户名不能为空";
//            keyboard.setCheckInfo(errStr,null);
        }
//        if (userName.trim().length()>8){
//            errStr="用户名最多为8位";
//            keyboard.setCheckInfo(errStr,null);
//        }
//        if (errStr==null){
            mainFrame.getContentPane().removeAll();
            mainFrame.getContentPane().setLayout(new BorderLayout());
            if (manButton.isSelected()==false)
                userSex="woman";
            String str="";
            try {
                runInfo.setTrainnerId(userName);
                runInfo.setTrainnerBirth(userBirth);
                runInfo.setTrainnerSex(userSex);
                runInfo.setLoginDate(ElfiiCommonUtil.getLocalCurrentDate(""));
                runInfo.setLoginTime(ElfiiCommonUtil.getLocalCurrentTime(""));

                long startTimeMillis=System.currentTimeMillis();
                Statement st = runInfo.getStatement1();
                str="select trainnerId from TrainningUser where trainnerId='"+userName+"'" ;
                ResultSet rs=st.executeQuery(str);
                if (rs.next()==false){
                    str="insert into TrainningUser (trainnerId,machineId) values ('"+userName+"','"+runInfo.getMachineId()+"')";
                    st.execute(str);
                }

                str="update TrainningUser set lastLoginDate='"+runInfo.getLoginDate()+"',lastLoginTime='"+runInfo.getLoginTime()+"',birth='"+userBirth+"',sex='"+userSex+"' where trainnerId='"+userName+"'";
                st.execute(str);
                str="update TrainningUser set IsUpload=2 where IsUpload=1 and trainnerId='"+userName+"'";
                st.execute(str);

                str="insert into TrainningLogin (machineId,trainnerID,loginDate,loginTime) values ('"+runInfo.getMachineId()+"','"+runInfo.getTrainnerId()+"','"+runInfo.getLoginDate()+"','"+runInfo.getLoginTime()+"')";
                st.execute(str);

                long endTimeMillis=System.currentTimeMillis();
                System.out.println("登录OK，Time:(1/1000) "+(endTimeMillis-startTimeMillis));
            } catch (Exception e) {System.out.print("login()  "+e+"   "+str);}
            ElfiiCommonGameSelect gameSelect = new ElfiiCommonGameSelect();
            gameSelect.setRunInfo(runInfo);
            mainFrame.getContentPane().add(gameSelect.createViewPanel(),BorderLayout.CENTER);
            mainFrame.setVisible(true);
//        }
    }

    public void dealBackButton(){
        mainFrame.getContentPane().removeAll();
        mainFrame.getContentPane().setLayout(new BorderLayout());
        ElfiiCommonWelcome welcome = new ElfiiCommonWelcome();
        welcome.setRunInfo(runInfo);
        mainFrame.getContentPane().add(welcome.createViewPanel(),BorderLayout.CENTER);
        mainFrame.setVisible(true);
    }

    public static String nZero(int zeroNumber) {
        String kkstr="";
        for (int i=0; i<zeroNumber; i++)
            kkstr=kkstr+"0";
        return kkstr ;
    }


    public JPanel createLoginPanel(){

        BufferedImage keyBgImage=null;
        BufferedImage comboxDownImage=null;
        BufferedImage manSelectImage=null;
        BufferedImage manUnselectImage=null;
        BufferedImage womanSelectImage=null;
        BufferedImage womanUnselectImage=null;

        String str;

        //先初始化，其他要用数据
        comboxPanel = new ElfiiCommonLoginCombox(comboxWidth,comboxHeight);
        comboxPanel.initDataList();

        manButton=new JButton();

        manButton.addActionListener( new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    comboxPanel.setComboxHide(true);
                    
                    userNamePanel.repaint();
                    
                    comboxPanel.repaint();
                    if (manButton.isSelected()==false){
                        manButton.setSelected(true);
                        womanButton.setSelected(false);
                    }
                    
                    ElfiiCommonUtil.playFeedbackAudio(FeedBackType.CLICK);
                    
                }
            });

        ImageIcon manNoSelectedIcon = new ImageIcon("resource-common/images/login/man_not_selected.png","");
        ImageIcon manSelectedIcon   = new ImageIcon("resource-common/images/login/man_selected.png","");
        manButton.setBackground(Color.black);
        manButton.setBorderPainted(false);
        manButton.setFocusPainted(false);
        manButton.setIcon(manNoSelectedIcon);
        manButton.setSelectedIcon(manSelectedIcon);
        manButton.setModel(new DefaultButtonModel() {
                public boolean isPressed(){
                    return false; 
                }
            }
            ) ;

        womanButton=new JButton();
        womanButton.addActionListener( new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    comboxPanel.setComboxHide(true);
                    userNamePanel.repaint();
                    comboxPanel.repaint();
                    if (womanButton.isSelected()==false){
                        womanButton.setSelected(true);
                        manButton.setSelected(false);
                    }
                    
                    ElfiiCommonUtil.playFeedbackAudio(FeedBackType.CLICK);
                }
            });

        ImageIcon womanNoSelectedIcon = new ImageIcon("resource-common/images/login/woman_not_selected.png","");
        ImageIcon womanSelectedIcon   = new ImageIcon("resource-common/images/login/woman_selected.png","");
        womanButton.setBackground(Color.black);
        womanButton.setBorderPainted(false);
        womanButton.setFocusPainted(false);
        womanButton.setIcon(womanNoSelectedIcon);
        womanButton.setSelectedIcon(womanSelectedIcon);
        womanButton.setModel(new DefaultButtonModel() {
                public boolean isPressed(){
                    return false; 
                }
            }
            ) ;
        str=runInfo.getTrainnerSex();
        if (str!=null && str.equals("woman")){
            womanButton.setSelected(true);
            manButton.setSelected(false);
        }else{
            womanButton.setSelected(false);
            manButton.setSelected(true);
        }

        birthYearField = new JTextField("",4);
        birthYearField.setBorder(null); //-可以去掉边框
        birthYearField.setBackground(Color.white);
        birthYearField.setForeground(ElfiiCommonConstant.Elfii_Blue);
        birthYearField.setCaretColor(ElfiiCommonConstant.Elfii_Blue);
        birthYearField.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,24));

        birthYearField.addFocusListener(new FocusListener() {
                public void focusGained(FocusEvent e)  {
                    comboxPanel.setComboxHide(true);
                    userNamePanel.repaint();
                    comboxPanel.repaint();
                    
                    birthYearDecreaseBtn.setVisible(true);
                    birthYearIncreaseBtn.setVisible(true);
                    
                    birthYearField.selectAll();
                }
                public void focusLost(FocusEvent e)  {
                	birthYearDecreaseBtn.setVisible(false);
                    birthYearIncreaseBtn.setVisible(false);
                }
            });

        birthMonthField = new JTextField("",2);
        birthMonthField.setBorder(null); //-可以去掉边框
        birthMonthField.setBackground(Color.white);
        birthMonthField.setForeground(ElfiiCommonConstant.Elfii_Blue);
        birthMonthField.setCaretColor(ElfiiCommonConstant.Elfii_Blue);
        birthMonthField.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,24));

        birthMonthField.addFocusListener(new FocusListener() {
                public void focusGained(FocusEvent e)  {
                    comboxPanel.setComboxHide(true);
                    userNamePanel.repaint();
                    comboxPanel.repaint();
                 	birthMonthDecreaseBtn.setVisible(true);
                    birthMonthIncreaseBtn.setVisible(true);
                    birthMonthField.selectAll();
                }
                public void focusLost(FocusEvent e)  {
                	birthMonthDecreaseBtn.setVisible(false);
                    birthMonthIncreaseBtn.setVisible(false);
                }
            });

        birthDayField = new JTextField("",2);
        birthDayField.setBorder(null); //-可以去掉边框
        birthDayField.setBackground(Color.white);
        birthDayField.setForeground(ElfiiCommonConstant.Elfii_Blue);
        birthDayField.setCaretColor(ElfiiCommonConstant.Elfii_Blue);
        birthDayField.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,24));
        birthDayField.addFocusListener(new FocusListener() {
                public void focusGained(FocusEvent e)  {
                    comboxPanel.setComboxHide(true);
                    userNamePanel.repaint();
                    comboxPanel.repaint();
                    
                 	birthDateDecreaseBtn.setVisible(true);
                    birthDateIncreaseBtn.setVisible(true);
                    birthDayField.selectAll();
                }

                public void focusLost(FocusEvent e)  {
                	birthDateDecreaseBtn.setVisible(false);
                    birthDateIncreaseBtn.setVisible(false);
                }
            });
        
        birthYearField.setEditable(false);
        birthMonthField.setEditable(false);
        birthDayField.setEditable(false);
        
        String nowDateStr=ElfiiCommonUtil.getLocalCurrentDate("");
        nowYear = Integer.parseInt(nowDateStr.substring(0,4));
        nowMonth = Integer.parseInt(nowDateStr.substring(4,6));
        nowDay = Integer.parseInt(nowDateStr.substring(6,8));

        str="2000-01-01";
        if (comboxPanel.getComboxAllNameListSize()>0)
            str=comboxPanel.getComboxAllBirthListElement(0);
        
        birthYear = Integer.parseInt(str.substring(0,4));
        birthMonth = Integer.parseInt(str.substring(5,7));
        birthDay = Integer.parseInt(str.substring(8,10));
        
        birthYearField.setText(str.substring(0,4));
        birthMonthField.setText(str.substring(5,7));
        birthDayField.setText(str.substring(8,10));

        str="";
        if (comboxPanel.getComboxAllNameListSize()>0)
            str=comboxPanel.getComboxAllNameListElement(0);

        userNameField = new JTextField(str,8);
        userNameField.setBorder(null); 
        userNameField.setBackground(Color.white);
        userNameField.setForeground(ElfiiCommonConstant.Elfii_Blue);
        userNameField.setCaretColor(ElfiiCommonConstant.Elfii_Blue);
        userNameField.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,28));
        userNameField.getDocument().addDocumentListener(new UserNameKeyboardChangeListener());
        
        userNameField.addFocusListener(new FocusListener() {
                public void focusGained(FocusEvent e)  {
                    setKeyboardTextFieldUserName();
                }
                public void focusLost(FocusEvent e)  {
                	keyboard.setTextField(null,maxUserNameSize);
                	if(userNameField.getText().trim().length()==0){
                		keyboard.setCheckInfo("用户名不能为空", null);
                	}
                }
            });

        comboxToggleButton=new JButton();

        comboxToggleButton.addActionListener( new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    if (comboxPanel.isComboxHide()==true)
                        comboxPanel.setComboxHide(false);
                    else
                        comboxPanel.setComboxHide(true);

                    comboxPanel.setFiltString(userNameField.getText());
                    comboxPanel.repaint();
                    userNamePanel.repaint();
                    ElfiiCommonUtil.playFeedbackAudio(FeedBackType.CLICK);
                }
            });
        ImageIcon comboxIcon   = new ImageIcon("resource-common/images/gw/gw_login_combox_down.png","");
        comboxToggleButton.setBackground(Color.black);
        comboxToggleButton.setBorderPainted(false);
        comboxToggleButton.setFocusPainted(false);
        comboxToggleButton.setIcon(comboxIcon);
        comboxToggleButton.setSelectedIcon(comboxIcon);
        comboxToggleButton.setModel(new DefaultButtonModel() {
                public boolean isPressed(){
                    return false; 
                }
            }
            ) ;

        comboxPanel.addMouseListener(new MouseAdapter(){
                public void mousePressed(MouseEvent e) {
                    comboxPanel.dealComboxMousePressed(e);
                }
            }
            );
        comboxPanel.addMouseMotionListener(new MouseAdapter(){
                public void mouseDragged(MouseEvent e) {
                    comboxPanel.dealComboxMouseDragged(e);
                }
            }
            );

        comboxPanel.setManButton(manButton);
        comboxPanel.setWomanButton(womanButton);
        comboxPanel.setUserNameField(userNameField);
        comboxPanel.setBirthYearField(birthYearField);
        comboxPanel.setBirthMonthField(birthMonthField);
        comboxPanel.setBirthDayField(birthDayField);

        keyboard = new Keyboard();
        keyboard.setTextField(null,maxUserNameSize);

        JPanel p = new JPanel() ;
        p.setLayout(null);
        p.setBackground(Color.black);

        userNamePanel = new UserNamePanel();
        userNamePanel.setBackground(Color.black);
        userNamePanel.setLayout(null);
        userNamePanel.add(userNameField);
        userNameField.setBounds(20,15,225,35);
        userNamePanel.add(comboxToggleButton);
        comboxToggleButton.setBounds(279,20,30,27);

//        HeadlinePanel headlinePanel = new HeadlinePanel();
//        headlinePanel.setBackground(Color.black);

        UserBirthPanel userBirthPanel = new UserBirthPanel();
        userBirthPanel.setBackground(Color.black);

        userBirthPanel.setLayout(null);

        userBirthPanel.add(birthYearField);
        birthYearField.setBounds(13,15,68,35);

        userBirthPanel.add(birthMonthField);
        birthMonthField.setBounds(100,15,36,35);

        userBirthPanel.add(birthDayField);
        birthDayField.setBounds(150,15,42,35);

//        p.add(headlinePanel);
//        headlinePanel.setBounds(50,80,600,22);
        
        birthYearDecreaseBtn = new JButton(new ImageIcon("resource-common/images/login/decrease.png"));
        
        p.add(birthYearDecreaseBtn);
        birthYearDecreaseBtn.setBounds(575, 15, 40, 30);
        birthYearDecreaseBtn.setContentAreaFilled(false);
        birthYearDecreaseBtn.setBorder(null);
        
        birthYearDecreaseBtn.setVisible(false);
//        birthYearDecreaseBtn.addActionListener(new )
        
        
        birthYearIncreaseBtn = new JButton(new ImageIcon("resource-common/images/login/increase.png"));
        
        p.add(birthYearIncreaseBtn);
        birthYearIncreaseBtn.setBounds(575, 108, 40, 30);
        birthYearIncreaseBtn.setContentAreaFilled(false);
        birthYearIncreaseBtn.setBorder(null);
        
        birthYearIncreaseBtn.setVisible(false);
        
        birthMonthDecreaseBtn = new JButton(new ImageIcon("resource-common/images/login/decrease.png"));
        
        p.add(birthMonthDecreaseBtn);
        birthMonthDecreaseBtn.setBounds(645, 15, 40, 30);
        birthMonthDecreaseBtn.setContentAreaFilled(false);
        birthMonthDecreaseBtn.setBorder(null);
        
        birthMonthDecreaseBtn.setVisible(false);
        
        
        birthMonthIncreaseBtn = new JButton(new ImageIcon("resource-common/images/login/increase.png"));
        
        p.add(birthMonthIncreaseBtn);
        birthMonthIncreaseBtn.setBounds(645, 108, 40, 30);
        birthMonthIncreaseBtn.setContentAreaFilled(false);
        birthMonthIncreaseBtn.setBorder(null);
        
        birthMonthIncreaseBtn.setVisible(false);
        
        birthDateDecreaseBtn = new JButton(new ImageIcon("resource-common/images/login/decrease.png"));
        
        p.add(birthDateDecreaseBtn);
        birthDateDecreaseBtn.setBounds(695, 15, 40, 30);
        birthDateDecreaseBtn.setContentAreaFilled(false);
        birthDateDecreaseBtn.setBorder(null);
        
        birthDateDecreaseBtn.setVisible(false);
        
        birthDateIncreaseBtn = new JButton(new ImageIcon("resource-common/images/login/increase.png"));
        
        p.add(birthDateIncreaseBtn);
        birthDateIncreaseBtn.setBounds(695, 108, 40, 30);
        birthDateIncreaseBtn.setContentAreaFilled(false);
        birthDateIncreaseBtn.setBorder(null);
        
        birthDateIncreaseBtn.setVisible(false);
        
        birthYearDecreaseBtn.addMouseListener(new BirthChangeListener());
        birthYearIncreaseBtn.addMouseListener(new BirthChangeListener());
        birthMonthDecreaseBtn.addMouseListener(new BirthChangeListener());
        birthMonthIncreaseBtn.addMouseListener(new BirthChangeListener());
        birthDateDecreaseBtn.addMouseListener(new BirthChangeListener());
        birthDateIncreaseBtn.addMouseListener(new BirthChangeListener());

        p.add(userNamePanel);
        userNamePanel.setBounds(150,43,320,67);

        p.add(comboxPanel);
        comboxPanel.setBounds(150,108,comboxWidth,comboxHeight);

        p.add(userBirthPanel);
        userBirthPanel.setBounds(550,43,200,67);

        p.add(manButton);
        manButton.setBounds(760,43,80,67);
        p.add(womanButton);
        womanButton.setBounds(840,43,80,67);

        JPanel keyPanel=keyboard.createKeyPanel();
        keyPanel.setBackground(Color.black);

        p.add(keyPanel);
        keyPanel.setBounds(150,240,785,331);

        JPanel infoPanel=keyboard.createInfoPanel();
        p.add(infoPanel);
        infoPanel.setBounds(150,10,250,30);

        p.requestFocus();  //-此处必须有，或者用tab键，获得焦点，鼠标点击不行！
        //System.out.println("是否焦点:"+p.isFocusOwner());
        comboxPanel.setUserNamePanel(userNamePanel);
        comboxPanel.setComboxHide(true);
        
        JLabel userNameLabel = new TitleLabel("用户名");
        JLabel birthDayLabel = new TitleLabel("生日");
        
        p.add(userNameLabel);
        userNameLabel.setFont(ElfiiCommonConstant.Trainning_Result_Prompt_Font);
        userNameLabel.setForeground(Color.white);
        userNameLabel.setBounds(60, 60, 80, 30);
        
        p.add(birthDayLabel);
        birthDayLabel.setFont(ElfiiCommonConstant.Trainning_Result_Prompt_Font);
        birthDayLabel.setForeground(Color.white);
        birthDayLabel.setBounds(490, 60, 80, 30);

        return p;
    }
    
    private void setBirthYear(int year){
    	birthYearField.setText(String.valueOf(year));
    	birthYearField.selectAll();
    }
    
    private void setBirthMonth(int month){
    	if(month<10){
    		birthMonthField.setText("0"+String.valueOf(month));
    	}
    	else{
    		birthMonthField.setText(String.valueOf(month));
    	}
    	birthMonthField.selectAll();
    	
    	if(month==2 && birthDay > 28){
			birthDay = 28;
			setBirthDay(birthDay,false);
		}
		else if((month==4||month==6||month==9||month==11) && birthDay == 31){
			birthDay = 30;
			setBirthDay(birthDay,false);
		}
    }
    
    private void setBirthDay(int day, boolean isActive){
    	if(day<10){
    		birthDayField.setText("0"+String.valueOf(day));
    	}
    	else{
    		birthDayField.setText(String.valueOf(day));
    	}
    	if(isActive)
    		birthDayField.selectAll();
    }
    
    boolean isPressed = false;
    
    private class BirthChangeListener extends MouseAdapter {
		
    	int count = 0;
    	
		@Override
		public void mouseReleased(MouseEvent e) {
			
			if(e.getButton()!=1)
				return;
			
			isPressed=false;
			count = 0;
		}

		@Override
		public void mousePressed(MouseEvent e) {
			
			if(e.getButton()!=1)
				return;
			
			final JButton btn = (JButton) e.getSource();
			
			isPressed=true;
			
			new Thread(){
				@Override
				public void run() {
					while(isPressed){
						count++;
						if(btn==birthYearDecreaseBtn){
							if(birthYear>1900)
							setBirthYear(--birthYear);
						}
						else if(btn==birthYearIncreaseBtn){
							if(birthYear==nowYear-1 && birthMonth>nowMonth)
								return;
							
							if(birthYear==nowYear-1 && birthMonth==nowMonth && birthDay>nowDay)
								return;
							
							if(birthYear<nowYear)
								setBirthYear(++birthYear);
						}
						else if(btn==birthMonthDecreaseBtn){
							if(birthMonth>1){
								setBirthMonth(--birthMonth);
							}
							
						}
						else if(btn==birthMonthIncreaseBtn){
							if(birthYear==nowYear && birthDay<=nowDay && birthMonth == nowMonth)
								return;
							
							if(birthYear==nowYear && birthDay>nowDay && birthMonth == nowMonth-1)
								return;
							
							if(birthMonth == 12)
								return;
							
							setBirthMonth(++birthMonth);
							
							
						}
						else if(btn==birthDateDecreaseBtn){
							if(birthDay>1){
								setBirthDay(--birthDay,true);
							}
						}
						else if(btn==birthDateIncreaseBtn){
							if(birthYear==nowYear && birthMonth==nowMonth && birthDay==nowDay)
								return;
							
							if(birthMonth==2 && birthYear%4==0 && birthDay == 29)
								return;
							
							if(birthMonth==2 && birthYear%4!=0 && birthDay ==28)
								return;
							
							if((birthMonth==4||birthMonth==6||birthMonth==9||birthMonth==11) && birthDay == 30)
								return;
							
							if(birthDay == 31)
								return;
							
							setBirthDay(++birthDay,true);
								
						}
						try{
						if(count<10){
							Thread.sleep(200);
						}
						else if(count<20){
							Thread.sleep(100);
						}
						else{
							Thread.sleep(50);
						}
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					}
				}
				
			}.start();
			
		}
		
	}

    public JPanel createViewPanel(){

        JButton okButton=new JButton();
        okButton.addActionListener( new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    dealOkButton();
                    ElfiiCommonUtil.playFeedbackAudio(FeedBackType.CLICK);
                }
            });

        JButton backButton=new JButton();
        backButton.addActionListener( new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    dealBackButton();
                    ElfiiCommonUtil.playFeedbackAudio(FeedBackType.CLICK);
                }
            });


        JPanel p = new JPanel() ;
        JButton homeButton=runInfo.createHomeButton();
        JPanel topPanel=ElfiiCommonUtil.createTopPanel(headline,backButton,homeButton);
        JPanel bottomPanel=ElfiiCommonUtil.createBottomPanelLevelSelect(okButton);
        p.setLayout(null);
        p.setBackground(Color.black);
        p.add(topPanel);
        topPanel.setBounds(0,0,1024,100);
        p.add(bottomPanel);
        bottomPanel.setBounds(0,668,1024,100);

        JPanel loginPanel=createLoginPanel() ;
        loginPanel.setBackground(Color.black);
        p.add(loginPanel);
        loginPanel.setBounds(0,100,1024,568);
        return p;
    }
    
//    public 


}
